-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] TalkRoom Comment 등록 API 구현 #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가된 내용 확인했습니다.
의견에 대한 답변만 남겨주시고 머지하시면 될 듯합니다 ~
수고하셨습니다 👍
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
class CommentControllerTest { | ||
|
||
@MockBean | ||
CommentService commentService; | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Test | ||
@DisplayName("유저가 토크방에 자신의 의견을 작성한다.") | ||
void writeComment() throws Exception { | ||
// given | ||
CommentCreateRequest request = CommentCreateRequest.builder() | ||
.content("의견을 작성하다") | ||
.build(); | ||
|
||
// when // then | ||
mockMvc.perform(post("/v1/talk-rooms/1/comments") | ||
.content(objectMapper.writeValueAsString(request)) | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("200")) | ||
.andExpect(jsonPath("$.status").value("OK")) | ||
.andExpect(jsonPath("$.message").value("OK")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Auth
에 담겨있는 userId를 넘겨주는 부분을 테스트에서 잘 처리하셨네요.
@MockBean
덕분에 controller -> service의 구간을 쉽게 통과할 수 있나요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네네!
@MockBean
을 사용하면 테스트 시에는 commentService가 직접 실행되는 것이 아니라 MockBean이 대신 실행되어, 해당 동작이 정상적으로 이루어졌다고 가정하고 테스트를 진행합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다. 잘 작성해주셔서 수정할 부분은 없는거 같습니다.
고생하셨습니다 👍
💡 연관된 이슈
close #24
📝 작업 내용
💬 리뷰 요구 사항
이번 코드는 간단하게 등록 API만 작성한거라 리뷰 요구 사항은 없습니다!